package com.cat.orm.core.convert;

import com.cat.orm.core.base.IBaseData;
import com.cat.orm.core.base.IBasePo;
import com.cat.orm.core.base.SimpleBasePo;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;


/**
 * 抽象的玩家数据转换器
 * @param <D>
 * @param <P>
 * @author Jeremy Feng
 */
public abstract class AbstractDataConverter<D extends IBaseData, P extends IBasePo> implements PersistenceDataConverter<D, P> {

    protected Class<D> baseDataClazz;
    protected Class<P> basePoClazz;

    @SuppressWarnings("unchecked")
    public AbstractDataConverter() {
        try {
            Type superClass = getClass().getGenericSuperclass();
            this.baseDataClazz = (Class<D>)(((ParameterizedType) superClass).getActualTypeArguments()[0]);
            this.basePoClazz = (Class<P>)(((ParameterizedType) superClass).getActualTypeArguments()[1]);
        } catch (Exception e) {
            logger.error("AbstractDataConverter error", e);
        }
    }

    @Override
    public Class<D> getDataClazz() {
        return baseDataClazz;
    }

    @Override
    public Class<P> getPojoClazz() {
        return basePoClazz;
    }

}